load("//:build_variables.bzl", "COPTS")
load("//tools/lint:linters.bzl", "clang_tidy_test")

package(
    default_visibility = ["//:android_cuttlefish"],
)

cc_library(
    name = "build_api_flags",
    srcs = ["build_api_flags.cc"],
    hdrs = ["build_api_flags.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:flag_parser",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/cache",
        "//cuttlefish/host/commands/cvd/fetch:credential_flags",
        "//cuttlefish/host/libs/web/cas:cas_flags",
        "//cuttlefish/host/libs/web:android_build_api",
        "//libbase",
    ],
)

clang_tidy_test(
    name = "build_api_flags_clang_tidy",
    srcs = [":build_api_flags"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "build_strings",
    srcs = ["build_strings.cc"],
    hdrs = ["build_strings.h"],
    deps = [
        "//cuttlefish/host/commands/cvd/fetch:get_optional",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/libs/web:android_build_string",
        "//cuttlefish/host/libs/web:chrome_os_build_string",
    ],
)

clang_tidy_test(
    name = "build_strings_clang_tidy",
    srcs = [":build_strings"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "credential_flags",
    srcs = ["credential_flags.cc"],
    hdrs = ["credential_flags.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:flag_parser",
    ],
)

clang_tidy_test(
    name = "credential_flags_clang_tidy",
    srcs = [":credential_flags"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "de_android_sparse",
    srcs = ["de_android_sparse.cc"],
    hdrs = ["de_android_sparse.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/libs/image_aggregator",
        "//libbase",
        "//libsparse",
    ],
)

clang_tidy_test(
    name = "de_android_sparse_clang_tidy",
    srcs = [":de_android_sparse"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "download_flags",
    srcs = ["download_flags.cc"],
    hdrs = ["download_flags.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/commands/cvd/fetch:get_optional",
    ],
)

clang_tidy_test(
    name = "download_flags_clang_tidy",
    srcs = [":download_flags"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "downloaders",
    srcs = ["downloaders.cc"],
    hdrs = ["downloaders.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:environment",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/commands/cvd/utils:common",
        "//cuttlefish/host/libs/web/http_client",
        "//cuttlefish/host/libs/web/http_client:curl_http_client",
        "//cuttlefish/host/libs/web/http_client:retrying_http_client",
        "//cuttlefish/host/libs/web:build_api",
        "//cuttlefish/host/libs/web:caching_build_api",
        "//cuttlefish/host/libs/web:credential_source",
        "//cuttlefish/host/libs/web:luci_build_api",
        "//cuttlefish/host/libs/web:oauth2_consent",
    ],
)

clang_tidy_test(
    name = "downloaders_clang_tidy",
    srcs = [":downloaders"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_test(
    name = "downloaders_test",
    srcs = ["downloaders_test.cpp"],
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/common/libs/utils:result_matchers",
        "//cuttlefish/host/commands/cvd/fetch:downloaders",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//libbase",
        "@fmt",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)

clang_tidy_test(
    name = "downloaders_test_clang_tidy",
    srcs = [":downloaders_test"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "extract_image_contents",
    srcs = ["extract_image_contents.cc"],
    hdrs = ["extract_image_contents.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:archive",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:result",
    ],
)

clang_tidy_test(
    name = "extract_image_contents_clang_tidy",
    srcs = [":extract_image_contents"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "fetch_cvd",
    srcs = ["fetch_cvd.cc"],
    hdrs = ["fetch_cvd.h"],
    copts = COPTS + [ "-Werror=sign-compare" ],
    deps = [
        "//cuttlefish/common/libs/utils:archive",
        "//cuttlefish/common/libs/utils:contains",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/fetch:build_strings",
        "//cuttlefish/host/commands/cvd/fetch:de_android_sparse",
        "//cuttlefish/host/commands/cvd/fetch:download_flags",
        "//cuttlefish/host/commands/cvd/fetch:downloaders",
        "//cuttlefish/host/commands/cvd/fetch:extract_image_contents",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/commands/cvd/fetch:fetch_tracer",
        "//cuttlefish/host/commands/cvd/fetch:host_package",
        "//cuttlefish/host/commands/cvd/fetch:host_tools_target",
        "//cuttlefish/host/commands/cvd/fetch:substitute",
        "//cuttlefish/host/commands/cvd/fetch:target_directories",
        "//cuttlefish/host/libs/config:fetcher_config",
        "//cuttlefish/host/libs/image_aggregator",
        "//cuttlefish/host/libs/web/http_client:curl_global_init",
        "//cuttlefish/host/libs/web:android_build",
        "//cuttlefish/host/libs/web:android_build_api",
        "//cuttlefish/host/libs/web:android_build_string",
        "//cuttlefish/host/libs/web:build_zip_name",
        "//cuttlefish/host/libs/web:chrome_os_build_string",
        "//cuttlefish/host/libs/web:luci_build_api",
        "//libbase",
    ],
)

clang_tidy_test(
    name = "fetch_cvd_clang_tidy",
    srcs = [":fetch_cvd"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "fetch_cvd_parser",
    srcs = ["fetch_cvd_parser.cc"],
    hdrs = ["fetch_cvd_parser.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:flag_parser",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/fetch:build_api_flags",
        "//cuttlefish/host/commands/cvd/fetch:vector_flags",
        "//libbase",
    ],
)

clang_tidy_test(
    name = "fetch_cvd_parser_clang_tidy",
    srcs = [":fetch_cvd_parser"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_test(
    name = "fetch_cvd_parser_test",
    srcs = ["fetch_cvd_parser_test.cpp"],
    deps = [
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/common/libs/utils:result_matchers",
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)

clang_tidy_test(
    name = "fetch_cvd_parser_test_clang_tidy",
    srcs = [":fetch_cvd_parser_test"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "fetch_tracer",
    srcs = ["fetch_tracer.cpp"],
    hdrs = ["fetch_tracer.h"],
    copts = COPTS,
    deps = ["@fmt"],
)

clang_tidy_test(
    name = "fetch_tracer_clang_tidy",
    srcs = [":fetch_tracer"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "get_optional",
    hdrs = ["get_optional.h"],
    copts = COPTS,
)

clang_tidy_test(
    name = "get_optional_clang_tidy",
    srcs = [":get_optional"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "host_package",
    srcs = ["host_package.cc"],
    hdrs = ["host_package.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:archive",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/commands/cvd/fetch:fetch_tracer",
        "//cuttlefish/host/commands/cvd/fetch:substitute",
        "//cuttlefish/host/libs/web:android_build",
        "//cuttlefish/host/libs/web:android_build_api",
        "//cuttlefish/host/libs/web:build_api",
        "//libbase",
    ],
)

clang_tidy_test(
    name = "host_package_clang_tidy",
    srcs = [":host_package"],
    tags = ["clang_tidy", "clang-tidy"],
)

proto_library(
    name = "host_pkg_migration_proto",
    srcs = ["host_pkg_migration.proto"],
)

cc_proto_library(
    name = "host_pkg_migration_cc_proto",
    deps = [":host_pkg_migration_proto"],
)

cc_library(
    name = "host_tools_target",
    srcs = ["host_tools_target.cc"],
    hdrs = ["host_tools_target.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
        "//cuttlefish/host/libs/web:android_build_string",
    ],
)

clang_tidy_test(
    name = "host_tools_target_clang_tidy",
    srcs = [":host_tools_target"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "substitute",
    srcs = ["substitute.cc"],
    hdrs = ["substitute.h"],
    copts = COPTS,
    deps = [
        ":host_pkg_migration_cc_proto",
        "//cuttlefish/common/libs/utils:environment",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:result",
        "//libbase",
        "@fmt",
        "@protobuf",
    ],
)

clang_tidy_test(
    name = "substitute_clang_tidy",
    srcs = [":substitute"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "target_directories",
    srcs = ["target_directories.cc"],
    hdrs = ["target_directories.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/host/commands/cvd/fetch:get_optional",
    ],
)

clang_tidy_test(
    name = "target_directories_clang_tidy",
    srcs = [":target_directories"],
    tags = ["clang_tidy", "clang-tidy"],
)

cc_library(
    name = "vector_flags",
    srcs = ["vector_flags.cc"],
    hdrs = ["vector_flags.h"],
    copts = COPTS,
    deps = [
        "//cuttlefish/common/libs/utils:flag_parser",
        "//cuttlefish/common/libs/utils:result",
        "//cuttlefish/host/libs/web:android_build_string",
        "//cuttlefish/host/libs/web:chrome_os_build_string",
    ],
)

clang_tidy_test(
    name = "vector_flags_clang_tidy",
    srcs = [":vector_flags"],
    tags = ["clang_tidy", "clang-tidy"],
)
